<?php

namespace Admin\Model;

use Think\Model;

class ActivityModel extends Model
{
	

	

	public function _select()
	{
		return $this->select();
	}

	public function _insert()
	{
		$data = array(
			'category_id'=>I('category_id'),
			'title'=>I('title'),
			'content'=>I('content'),
			//'cover'=>I('cover'),
			'description'=>I('description'),
			'position'=>I('position'),
			'createtime'=>time(),
		);
		$result = upload('Activity_Image');

        $id = $this->add($data);

        if (isset($result['image'])) {
            $this->where(['id' => $id])
                ->save(['cover' => C('UPLOAD_DOMAIN') . $result['image']['url']]);
        }

        return $id;
	}

	public function _update()
	{

		$data = array(
			'category_id'=>I('category_id'),
			'title'=>I('title'),
			'content'=>I('content'),
			//'cover'=>I('cover'),
			'description'=>I('description'),
			'position'=>I('position'),
			'createtime'=>time(),
		);
		$result = upload('Activity_Image');

        $id = $this->save($data);

        if (isset($result['image'])) {
            $this->where(['id' => $id])
                ->save(['cover' => C('UPLOAD_DOMAIN') . $result['image']['url']]);
        }

        return $id;
	}

	public function _delete()
	{
		$id = I('post.id', 0, 'intval');
		return $this->where(['id'=>$id])->delete();
	}

	public function __ioT()
	{
		static $arr = [];

		$m = module();
		$c = controller();
		$a = action();

		$c->$a();

	}

	

}